package redis_demo

import (
	"context"
	"fmt"
	"github.com/go-redis/redis"
	"os"
)

var ctx = context.Background()

func TestRedis() {
	client := testRedisConnection()
	testRedisString(client)
}

func testRedisConnection() *redis.Client {
	client := redis.NewClient(&redis.Options{
		Addr:     "127.0.0.1:6379",
		Password: "",
		DB:       0,
	})

	_, err := client.Ping().Result()
	if err != nil {
		fmt.Printf("Connect redis error %v", err)
		os.Exit(1)
	}
	return client
}

func testRedisString(client *redis.Client) {
	client.Set("aa", "bbb", 0)
	v, _ := client.Get("aa").Result()
	fmt.Println(v)
	fmt.Println(v)
	fmt.Println(v)
}
